package financial.sharing.center.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.system.model.entity.SysAdmin;
import financial.sharing.center.system.service.SysAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SysAdminController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/7
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/system/sys/admin/")
public class SysAdminController {
    
    @Autowired
    private SysAdminService sysAdminServiceImpl;

    @PostMapping(value = "get/all/sys/admin")
    public R getAllSysUser(String selectUserName,
                           Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<SysAdmin> result = this.sysAdminServiceImpl.getAllSysAdmin(selectUserName);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/sys/admin")
    public R createOneSysUser(String userName,
                              String userPassword){
        Integer result = this.sysAdminServiceImpl.createOneSysAdmin(userName,userPassword);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/sys/admin")
    public R compileOneSysUser(@RequestBody SysAdmin sysAdmin){
        Integer result = this.sysAdminServiceImpl.compileOneSysAdmin(sysAdmin);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/sys/admin")
    public R deleteOneSysUser(Integer id){
        Integer result = this.sysAdminServiceImpl.deleteOneSysAdmin(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }
}
